package gateway

import (
	"core/config"
	"fmt"
	"net/http"
	"net/http/httputil"
)

type Module struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

var ModuleMap map[string]Module

func init() {
	ModuleMap = make(map[string]Module)
}

func Add(name string, module Module) {
	ModuleMap[name] = module
}

func Remove(name string) {
	delete(ModuleMap, name)
}

func director(req *http.Request) {
	fmt.Println(req.URL.RequestURI())
}

func Gateway() {
	proxy := &httputil.ReverseProxy{Director: director}
	http.ListenAndServe(fmt.Sprintf(":%d", config.Config.Gateway.Port), proxy)
}
